<?php 
class users_Form_FrmUser extends Zend_Form
{
	public function frmuser($frm = null)
    {
    	$db = new Application_Model_DbTable_DbGlobal();
    	$gender = new Zend_Form_Element_Select('gender');
    		$gender->setMultiOptions(array("Mr"=>"Mr","Ms"=>"Ms","Miss"=>"Miss","PHD"=>"PHD","DR"=>"DR",));
    		$gender->setAttribs(array('class'=>'form-control chzn-select validate[required]',));

    	$id_code = new Zend_Form_Element_Text('id_code');
    		$id_code->setAttribs(array('class'=>'form-control validate[required]',));
    		
    	$fullname = new Zend_Form_Element_Text('fullname');
    		$fullname->setAttribs(array('class'=>'form-control validate[required]',));
    	$username = new Zend_Form_Element_Text('username');
    	
    		$username->setAttribs(array('class'=>'form-control validate[required]','Onkeyup'=>'getfillterUserType()'));
    	$email = new Zend_Form_Element_Text('email');
    	
    		$email->setAttribs(array('class'=>'validate[required,custom[email]] form-control','Onkeyup'=>'getfillterUserType()'));
    	$phone = new Zend_Form_Element_Text('phone');
    	
    		$phone->setAttribs(array('class'=>'validate[required] form-control','Onkeyup'=>'getfillterUserType()'));
    	$old_password = new Zend_Form_Element_Password('old_password');
    	
    		$old_password->setAttribs(array('class'=>'validate[required,minSize[5]] form-control',));
    	$password = new Zend_Form_Element_Password('password');
    	
    		$password->setAttribs(array('class'=>'validate[required,minSize[5]] form-control',));
    	$confirm_password = new Zend_Form_Element_Password('confirm_password');    	
    		$confirm_password->setAttribs(array('class'=>'validate[required,equals[password]] form-control',));
    	
    	
		$rs = $db->getGlobalDb('SELECT user_type_id,user_type FROM tbwu_acl_user_type where user_type_id');
		$options = array(''=>'--- ជ្រើសរើសប្រភេទអ្នកប្រើប្រាស់ ---');		
		foreach($rs as $read) $options[$read['user_type_id']]= $read['user_type'];
		$user_type_id = new Zend_Form_Element_Select('user_type');		
    	$user_type_id->setMultiOptions($options);
    	$user_type_id->setAttribs(array(
    		'id'=>'user_type_id',
    		'class'=>'form-control chzn-select validate[required]',
    	));
    	
    	$db_branch = $db->getGlobalDb("SELECT `branch_id`,`branch_name` FROM `tbwu_branch` WHERE `branch_id` !=''");
    	$options_branch = array(''=>'--- ជ្រើសរើសប្រភេទអ្នកប្រើប្រាស់ ---');
    	foreach($db_branch as $read_branch) $options_branch[$read_branch['branch_id']]= $read_branch['branch_name'];
    	$branch_name = new Zend_Form_Element_Select('branch_name');
    	$branch_name->setMultiOptions($options_branch);
    	$branch_name->setAttribs(array('id'=>'branch_name',	'class'=>'form-control chzn-select validate[required]',	));
    	
    	$id = new Zend_Form_Element_Hidden('id');
    	$photo = new Zend_Form_Element_File('photo');
    	$this->addElements(array($id_code,$branch_name,$photo,$id,$gender,$fullname,$username,$email,$phone,$password,$confirm_password,$user_type_id,$old_password));    	
    	if($frm !=""){
    		$id->setValue($frm['user_id']);
    		$gender->setValue($frm['title']);
    		$fullname->setValue($frm['fullname']);
    		$username->setValue($frm['username']);
    		$email->setValue($frm['email']);
    		$phone->setValue($frm['phone']);
    		$branch_name->setValue($frm['branch_id']);
    		$id_code->setValue($frm['id_code']);
//     		$password->setValue($frm['password']);
    		$user_type_id->setValue($frm['user_type_id']);
    		$photo->setValue($frm['photo']);
    		
    	}
    	return $this;
     }
}
?>
